Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards » Computer Science « Back to Discussion



Computer Science

#Eternal Warrior#'s Avatar
New kid on the Block

Joined: 14 Oct 2008
Post: 26
12 Mar 2009 20:54:35 IST
0 People liked this
8
589 View Post
whts d diffrence btween for loop and while loop..?? i mean..cn both of dem b used in d same sense..
None

whts d diffrence btween for loop and while loop..??i mean..cn both of dem b used in d same sense...??


Share this article on:

Comments (8)

vat kat's Avatar

Cool goIITian

Joined: 11 Mar 2009
Posts: 78
12 Mar 2009 21:09:54 IST
1 people liked this

(do while) loop  just requires the starting point or initializtion for a variable .there is no specification for ending in the start and thus checks the condition of termination after going thru processing of its body where it encounters the condition to terminate or to cntinue

 

whereas in for and while  loop ,it checks all the conditions at the start  and thus work accordingly the same .

 

yest there is no differ as such .only it depends on the comfortability of user


Blazing goIITian

Joined: 9 Oct 2008
Posts: 546
13 Mar 2009 03:09:05 IST
0 people liked this

hey shashank hav u not studied in XI class. How can u ask this foolish thing. It irritates me a lot. Don't think I'm commenting u and discouraging u but plz mate study computers bcz its' the coolest thing in the world ever.
Bipin Dubey's Avatar

Forum Expert
Joined: 23 Jan 2007
Posts: 7942
13 Mar 2009 14:39:15 IST
2 people liked this

More or less for and while loop are same, only syntax differs. Its the do while loop which differs in the sense that the loop is executed at least once.
ABINASH's Avatar

Hot goIITian

Joined: 20 Apr 2007
Posts: 131
13 Mar 2009 14:56:02 IST
2 people liked this

Hey.... a FOR loop is generally used when u can predetermine the number of times u wanna run the loop. And a WHILE loop is generally used when u wanna run the code until u satisfy a condition. U may note that wateva u can do in a FOR loop, can b done by a WHILE loop bt the reverse may not b true. U can also use the FOR loop to check boolean algebraic conditions as in for ( ; ans! = TRUE; ).....

hope this helps.....

and a special request to Mr Ankur Goel... try to have a control on ur tongue..... mind it.... If u cant be polite, then u r not welcome.... Doubts lyk this can b genuine, if u feel nethn strange abt this, try nt to answer than pukin ur damn "IRRITATION" on sum1 else...

#Eternal Warrior#'s Avatar

New kid on the Block

Joined: 14 Oct 2008
Posts: 26
2 Apr 2009 20:59:55 IST
0 people liked this

heyy..mr ankur goyel..wht do ya think u r..??? i had a doubt n i askd it..

Vikram Saxena's Avatar

Forum Expert
Joined: 1 Apr 2007
Posts: 3733
22 Apr 2009 07:43:24 IST
1 people liked this

For loops are used when you know how many times you need to loop. While loops are used to loop until an event occurs. Also, note that whatever you can do with a for loop, you can do it with a while loop (just add a variable that increments in the while loop and uses it to break out of the loop when the variable reaches a certain value). However, the reverse is not true (whatever you can do with a while do can not be done in a for loop).

-wish you good luck for the future


New kid on the Block

Joined: 14 Apr 2009
Posts: 9
26 Apr 2009 23:45:41 IST
1 people liked this

not more difference dear your can use in same sense really

 

only if you want to give increment condition in while loop in () it is not possiable as for loop 

 

in while loop you can give only checking condition and you will set increment /decrement in { .. } block

while(condition)

{

i++;

}

but in for you can use as this type also

for(i=0; i<10; i++ )

{

}

i=0;

for(; i<10; i++ )

{

}

i=0;

for(; i<10;)

{

i++;

}

three types you can use for loop

 

 

pankaj's Avatar

Cool goIITian

Joined: 11 May 2009
Posts: 43
11 May 2009 12:06:44 IST
2 people liked this

there is a difference of convinience  , while loop is little tricky and long as u have to initialise the variable before d while() and u have to write an extra statement for d icrement or decrement  

but in for loop u can declare or ++ or -- in a singe for( ; ;) statement which saves time.




Quick Reply


Reply

Some HTML allowed.
Keep your comments above the belt or risk having them deleted.
Signup for a avatar to have your pictures show up by your comment
If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team
Free Sign Up!

Preparing for IIT-JEE ?

Arihant Revision Package for IIT JEE - Books, Practice Tests + Rank Predictor


@ INR 1,995/-

For Quick Info

Name

Mobile No.

Find Posts by Topics

Physics.

Topics

Mathematics.

Chemistry.

Biology

Parents

Board

Fun Zone

Sponsored Ads