954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

boolean expression

How do i terminate a loop.

i have written

for(int i = 0; students; i++)

but it keeps on going forever and will not stop.

tom1989
Newbie Poster
10 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Look up the definition of a for loop. What do each of the parts of the loop do? Do your parts comply?

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

Assuming that students is an integer value then setting your for() loop like this should fix your problem:

for(int i = 0; i < students; i++)
Xavier2k
Newbie Poster
9 posts since Oct 2007
Reputation Points: 31
Solved Threads: 1
 

Assuming that students is an integer value then setting your for() loop like this should fix your problem:

for(int i = 0; i < students; i++)

i tired but i get this error msg
ISO C++ forbids comparison between pointer and integer \
?????

tom1989
Newbie Poster
10 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

What is students? Can you show me the declaration for it?

Xavier2k
Newbie Poster
9 posts since Oct 2007
Reputation Points: 31
Solved Threads: 1
 
What is students? Can you show me the declaration for it?


studentData studentss[100];
int numberOfStudents = 0;


is that wat u mean by declaration ??

tom1989
Newbie Poster
10 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 
for(int i = 0; students[i]; i++)
Xavier2k
Newbie Poster
9 posts since Oct 2007
Reputation Points: 31
Solved Threads: 1
 
for(int i = 0; students[i]; i++)


now the error is
could not convert `students[i]' to `bool'

tom1989
Newbie Poster
10 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Do what I said, please

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 
Look up the definition of a for loop. What do each of the parts of the loop do? Do your parts comply?

I have, i done this before i posted this question! it says that the boolean expression is used to test condition to determine when the loop should terminate. The test condition must always involve comparing the value of the counter variable with some numerical limit. Which in this case was[i]

but im unsure still.
should i use a true false statement ??

tom1989
Newbie Poster
10 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 
for(int i=0; i<noofstudents; i++)


i think this will help you out assuming noofstudents contains the value for the no of times you want to run the loop...or i.e no of students of type studentdata...

tracethepath
Junior Poster in Training
54 posts since Jul 2007
Reputation Points: 8
Solved Threads: 4
 

thankx

tom1989
Newbie Poster
10 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

I have, i done this before i posted this question! it says that the boolean expression is used to test condition to determine when the loop should terminate. The test condition must always involve comparing the value of the counter variable with some numerical limit. Which in this case was [i]

but im unsure still. should i use a true false statement ??


In the for statement you posted for(int i = 0; students[i]; i++) , what is your comparison statement? What is it comparing?

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You