C declaration expected for "while" loop?

Hey guys, I'm currently learning C and have taken the source code from a tutorial . Since the program terminates after a certain input, I wanted to experiment a bit and try inserting a loop.

I've already tried it with various for and while loops, but every time I get an error for "for" and "while" that a declaration is expected. It also tells me that both while and for generate a syntax error. I've attached a screenshot of it below.

I copied the loops as I found them online, but none of them seem to work. What am I doing wrong?

I am using Microsoft Visual Studio Community 2022 version 17.7.5.

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
12 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
jort93
1 year ago

Well, it must be in a class first in C.

In addition, this is an endless loop that does nothing and the code after that is never reached. Probably you want to remove the semicolon, and I don’t know what you want to achieve.

jort93
1 year ago
Reply to  vb2010user

The semicolon means the loop is over there.

Takidoso
11 months ago
Reply to  jort93

Are you sure you don’t mean anything like C++ here (C is subset of C++)

jort93
11 months ago
Reply to  Takidoso

The question is C, so I assume that the C is.

NorbertWillhelm
1 year ago

The code must be in a function.

Use the main entry spunk main.

int main(void) {

//Your code

}

gogogo
1 year ago

You must be within a method.

Write before:

int main( int argc, char ** argv ) {

Write after:

}

gogogo
1 year ago
Reply to  vb2010user

At the end of the line with the ‘while’ is a semicolon. That’s the trouble. Take it away.

gogogo
1 year ago

The block of the While Bow was the empty statement;

There was an endless loop. That’s why he didn’t come to the ‘float number’.

Very typical beginners.