expected 'while' before '}' token error

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 998 Views - Last Post: 29 December 2012 - 05:06 PM Rate Topic: -----

#1 barcodelll  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-December 12

expected 'while' before '}' token error

Posted 29 December 2012 - 07:08 AM

i'm sorry if this question is shouldn't be asked because maybe it's too easy(i guess), but i do really don't know how to solve this. i've tried to put the 'while' before the last '}' (which i know it won't solve the problem. just a little bit desperate though).

and i've looking for answers in many sources including this forum. but i'm not founding the answer yet. so please, teach me master! :D/>


okay, here's the code pieces where the error notification comes up:

(for language reason i can't put the whole code or should i?)
it's a driver file for a tree data structure

      		     		system ("clear");
      		}
		{
      		while(pil!=5);
		
		}
	}
     }
   } //it says that the expected while before '}' should be here
}



thanks in advance, and i'm sorry for my bad english :)

Is This A Good Question/Topic? 0
  • +

Replies To: expected 'while' before '}' token error

#2 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,686
  • Joined: 13-March 10

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 07:13 AM

Are you using a while-loop or a do-while loop?
If its while loop it should be somethign like:

while(condition){
//do something

}
Was This Post Helpful? 0
  • +
  • -

#3 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 07:13 AM

You have miss-matched braces:
03	        {
04	            while(pil!=5);


Was This Post Helpful? 0
  • +
  • -

#4 barcodelll  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-December 12

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 07:21 AM

View Postdarek9576, on 29 December 2012 - 07:13 AM, said:

Are you using a while-loop or a do-while loop?
If its while loop it should be somethign like:

while(condition){
//do something

}


it's a do while loop, (it'll stop when the 'pil'=5 just to make sure that i'm not misunderstood)
what should i do then?

View PostAKMafia001, on 29 December 2012 - 07:13 AM, said:

You have miss-matched braces:
03	        {
04	            while(pil!=5);



miss-matched braces? i don't get it, is there something wrong with the braces? i'm so sorry, i do really need more practices :(
Was This Post Helpful? 0
  • +
  • -

#5 barcodelll  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-December 12

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 07:32 AM

i need some help here please if you know something about this, teach me thanks! \:D/
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 4003
  • View blog
  • Posts: 12,354
  • Joined: 25-December 09

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 07:34 AM

Yes there is something wrong with your braces. A do/while statement looks like:
do
{
   // Do something.
} while(condition);


And remember that for every opening brace { you must have a closing brace }.

You may also want to study this link: Control Structures.

Jim

This post has been edited by jimblumberg: 29 December 2012 - 07:34 AM

Was This Post Helpful? 0
  • +
  • -

#7 FrostHeart07  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 13
  • Joined: 25-December 12

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 07:41 AM

What are the braces before and after while(pil!=5) trying to accomplish in your code? I think you don't need them... unless the indention is wrong?

system ("clear");
      		} //I'm guessing this is the closed brace for the do-while loop?
		{//And I think you don't need this brace.
      		while(pil!=5);

                }// You don't need this one too.
	}
     }
   }
}

Was This Post Helpful? 0
  • +
  • -

#8 barcodelll  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-December 12

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 07:51 AM

View Postjimblumberg, on 29 December 2012 - 07:34 AM, said:

Yes there is something wrong with your braces. A do/while statement looks like:
do
{
   // Do something.
} while(condition);


And remember that for every opening brace { you must have a closing brace }.

You may also want to study this link: Control Structures.

Jim


thank you jimblumberg!
so it means there's missing braces for some part right? i'll fix the indentation right away \:D/
but there's nothing wrong with the do while loop right? it's just about the missing braces right? :o
Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg  Icon User is offline

  • member icon


Reputation: 4003
  • View blog
  • Posts: 12,354
  • Joined: 25-December 09

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 07:57 AM

Quote

but there's nothing wrong with the do while loop right? it's just about the missing braces right?

I don't know, there may be other issues with your do/while loop. You haven't shown enough code to tell. If fixing the braces doesn't fix your problem, post the complete program along with the complete error messages exactly as they appear in your development environment.


Jim
Was This Post Helpful? 0
  • +
  • -

#10 FrostHeart07  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 13
  • Joined: 25-December 12

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 08:03 AM

Yeah, I agree, we can't really see the problem without the whole code.
Was This Post Helpful? 0
  • +
  • -

#11 barcodelll  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-December 12

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 08:22 AM

i hope you guys can get what it means, because i can't translate the whole things in the program :D

here's the full code

#include "tree.h"
#include "tree.c"
#include <stdio.h>

char ch;
int pil;

int main(){	
	do
{
	system("clear");
	printf("======MAIN MENU=====\n");
	printf("1.mulai cerita\n");
	printf("2.Menambah Cerita Baru\n");
	printf("3.Exit\n");

	printf("Ada sebuah nama di negeri yeulot, nama yang sudah termahsyur dan terdapat di mana-mana, di dinding restoran, warnet, wartel, warnas, dan warpas. OYOL. begitulah nama tersebut dipampag dengan tulisan WANTED diatasnya. Kira-kira bersembunyi dimanakah ia? a.kolam renang b.restoran");
	printf("Masukan Pilihan Anda:");scanf("%c",&ch);
	switch(ch)
	{
		case 'a' :
			{
			printf("a.blabla x.mati y.minum");
			printf("Masukan Pilihan Anda:");scanf("%c",&ch);
			switch(ch)
				{
					case 'x' :
					{	
						printf("x.blabla y.kolam renang z.kastil");
						printf("masukkan pilihan anda");scanf("%c",&ch);
						switch(ch)
						{
							case 'z' :
								{
								 printf("z.blabla tekan y.");
								 printf("masukkan pilihan anda: ");
								 scanf("%c",&ch);
								}
							case 'y' :
								{
								 printf("y.blabla m.gorila n.warung");
								 printf("masukkan pilihan anda: ");
								 scanf("%c",&ch);
								}
						default:
							{	
							printf("anda salah masukkan angka");
							}
						}
					}
			      break;
			case 'y' :
				{	
					printf("y. blabla m.gorila n.warung");
					printf("masukkan pilihan anda: ");
					scanf("%c",&ch);
					switch(ch)
						{
						case 'm' :
							{	
								printf("m. tekan n");
								printf("masukkan pilihan anda: ");
								scanf("%c",&ch);
							}
						case 'n' :
							{	
								printf("n. blabla");
								scanf("%c",&ch);
							}
						default:
							{	
								printf("anda salah memasukkan huruf");
							}
						}
		 			break;

	case 'b' :
		{
			printf("b. blablabla");
			scanf("%c",&ch);
		}
		break;
	case 'e' : 
		{ 	
			printf("Terima Kasih \n");
		}
		break;
	default: 
		{	
			printf("Pilihan Anda Salah Besar Cooy");
		}
		  break;

		}

      system ("clear");
      }

       	while(pil!=5);
			}
		    }
		}
	}		
}



thanks in advance \:D/
Was This Post Helpful? 0
  • +
  • -

#12 jimblumberg  Icon User is offline

  • member icon


Reputation: 4003
  • View blog
  • Posts: 12,354
  • Joined: 25-December 09

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 08:26 AM

So do you have some kind of problem with your code? If you get compile errors post the complete error messages, exactly as they appear in your development environment.

Jim
Was This Post Helpful? 0
  • +
  • -

#13 barcodelll  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-December 12

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 08:45 AM

View Postjimblumberg, on 29 December 2012 - 08:26 AM, said:

So do you have some kind of problem with your code? If you get compile errors post the complete error messages, exactly as they appear in your development environment.

Jim


oh sorry jim, i forgot to put the error message :D
the only error message that appear is this

(note: i use gcc)

in function 'main':
103:2: error: expected 'while' before '}' token


that's all \:D/
Was This Post Helpful? 0
  • +
  • -

#14 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 08:51 AM

I don't do C, but if your indentation was a bit better, you will notice you have too many closing braces "}"
Was This Post Helpful? 0
  • +
  • -

#15 sirgeek  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 18-December 12

Re: expected 'while' before '}' token error

Posted 29 December 2012 - 08:58 AM

I would suggest that you start over, but this time try to organise your code in a way that you can see which brackets go with which

Example
#include <something.h>

int main()
{
   do
   {
      something()
      {
         organiseCode();
      }
   }while(I give a fuck);
   
   return 0;
}


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2