Hi All,

A simple questions, can someone let me know the syntax of for loop e.g if i want to print my name 100 times ?

Thanks in advance.

Recommended Answers

All 3 Replies

There is a tutorial "pasted" to the top of this forum. Otherwise, this sounds far to much like homework for me to even want to give you any other answer.

Hi All,

A simple questions, can someone let me know the syntax of for loop e.g if i want to print my name 100 times ?

Thanks in advance.

Actually thing is that i have tried various syntax but seems nothing is working for me, although it is a novice question, but it is getting on to me :(, one of the exampls which i tried is,

#! /bin/sh
for ( i=0; (i>10); i++ )
do
echo "$i :"
done

Error which i got is below,

syntax error at line 2: `(' unexpected


Any help

Well, don't put i > 10 in parens.

Edit: You also realise (I hope), that you are setting i to zero in the first part of that, and incrementing i in the last part. In the second, you are saying that the loop should continue to run as long as i is greater than 10, but since you set i to zero in the first part, it exits the loop before ever doing anything. I assume you meant i < 10. I.e. the loop should continue running as long as i is less than ten.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.