| | |
while loop issue
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Can I do this?
the function I'm calling, is returning a 3, but the variable in the while loop is equal to 1...
I'm not sure what is happening in this statement, Originally I thought it would just always evaluate to true and loop forever since, variable would be successfully set to functionCall()'s return value, therefore evaluating to 1, and 1 does not equal zero, so that too would evaluate to 1 (true) and loop forever... but it sets variable to 1 and then exits the while loop--what's going on?
functionCall() gets input from the user so I can only call it once really, I was going for
c++ Syntax (Toggle Plain Text)
while(variable=functionCall()!=0){ /* ... */ }
the function I'm calling, is returning a 3, but the variable in the while loop is equal to 1...
I'm not sure what is happening in this statement, Originally I thought it would just always evaluate to true and loop forever since, variable would be successfully set to functionCall()'s return value, therefore evaluating to 1, and 1 does not equal zero, so that too would evaluate to 1 (true) and loop forever... but it sets variable to 1 and then exits the while loop--what's going on?
functionCall() gets input from the user so I can only call it once really, I was going for
while(functionCall()!=0){ } , but then I wouldn't be able to check the return value within the loop. I could do something else but I wanted to use this method, so I'm just wondering what it's actually doing. I wake up! And my mind's out, never again will I sell out. Converting vegetarians.
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
•
•
Join Date: Aug 2008
Posts: 71
Reputation:
Solved Threads: 10
you should try something like this:
...
because it seems to me that variable is given the value of evaluation: functionCall()!=0, so you just need to use one more pair of brackets...
I hope this helps
C++ Syntax (Toggle Plain Text)
while ((variable = functionCall())!=0)
because it seems to me that variable is given the value of evaluation: functionCall()!=0, so you just need to use one more pair of brackets...
I hope this helps
@da penguin, oh right, I forgot about right->left order, and you're right it was looping forever--there are two loops working together and I was mistaken with which loop I was in at what time.
@Alibeg, it worked great, thank you!
@Alibeg, it worked great, thank you!
I wake up! And my mind's out, never again will I sell out. Converting vegetarians.
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
![]() |
Similar Threads
- Pyramid Issue (Visual Basic 4 / 5 / 6)
- cannot start up XP - stuck in restart loop, keyboard frozen (Windows NT / 2000 / XP)
- While loop issue (C++)
- infinite loop... (C++)
- Primary Key Issue (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: extracting a sentence
- Next Thread: CHAR Key Up and Key Down
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






