473,383 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

if else brackets problem

18
Expand|Select|Wrap|Line Numbers
  1. for (i=0; i<8; i++)
  2.  {
  3.      if(score[i]==-2)
  4.      {
  5.          if(i<3)
  6.          {
  7.             for (j=0; j<3; j++)
  8.             {
  9.                 if (P[i][j]=='\0')
  10.                 {
  11.                    P[i][j]='O';
  12.                    j=3;
  13.                 }
  14.             }
  15.             else if (i<3 && i<6)I get a message here: "expected primary expression before "else"" and "expected ';' before else".
  16.             {  
  17.                  for (j=0; j<3; j++)
  18.                  {
  19.                  //...........lots of code removed here
  20.              }
  21.  
  22.  
  23.  
  24.          }
  25.      }
  26.      break;     
  27.  }   
When I try to compile it, I get the above message.
WHY???
Mar 10 '08 #1
4 2377
Sick0Fant
121 100+
Your post is probably going to get taken down (you're not supposed to post whole sections of code).

But, right off the bat, I can see that, at least at one point, you nested an "else if" inside of an "else if" without any "if" to proceed it.

It looks like you possibly misunderstood the syntax of if/else if/ else.

Correct:
Expand|Select|Wrap|Line Numbers
  1. if (something){
  2. //
  3. }
  4.  
  5. else if (something){
  6. //
  7. }
  8.  
  9. else{
  10. //
  11. }
  12.  
You seem to be doing
Expand|Select|Wrap|Line Numbers
  1. if(something){
  2.          //
  3.          else if (something){
  4.                       //
  5.          }
  6. //
  7. }
Mar 10 '08 #2
Ganon11
3,652 Expert 2GB
As Sick0faint said, posting a whole huge section of code isn't usually a good idea. Say this was a homework assignment, and you posted innocently enough asking for help. What's to stop a classmate from hopping online and stealing your whole solution? Now you're both in trouble for cheating, when you were just asking for help. By limiting the amount of code you post at a time, we can limit these occurrences.

In this case, your else if { is directly following a for loop - and there is no such thing as for (...) {...} else if (...) {...}, etc. etc.
Mar 10 '08 #3
cube
18
As Sick0faint said, posting a whole huge section of code isn't usually a good idea. Say this was a homework assignment, and you posted innocently enough asking for help. What's to stop a classmate from hopping online and stealing your whole solution? Now you're both in trouble for cheating, when you were just asking for help. By limiting the amount of code you post at a time, we can limit these occurrences.

In this case, your else if { is directly following a for loop - and there is no such thing as for (...) {...} else if (...) {...}, etc. etc.
The amount of code that I posted was a tiny piece of the assignment.
Is there any way else to express the problem without posting the code?

About my problem now, probably the if else isn't a good solution to my problem.
Should I give it one more try or should I look for sth else?
Mar 10 '08 #4
sanctus
84
The amount of code that I posted was a tiny piece of the assignment.
Is there any way else to express the problem without posting the code?

About my problem now, probably the if else isn't a good solution to my problem.
Should I give it one more try or should I look for sth else?
If you follow Sick0Fant's suggestion the for-if-else if etc. should work, I do not see the point though in saying:
Expand|Select|Wrap|Line Numbers
  1. else if (i<3 && i<6)
  2.  
Because if i is smaller than 3 it is always smaller than 6...
Mar 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: deko | last post by:
Do I need to use curly brackets in PHP if .. else statements? other constructs? Does it matter? What are Best Practices? Why? thanks in advance... This seems to work WITHOUT curly brackets:...
1
by: Veverita | last post by:
Hi there I'm hoping that someone can help me with a question I have about javascript syntax. I got an html page that uploads an image and some text field to a database. What I'd like to do...
3
by: Eric Ellsworth | last post by:
Hi all, Does anyone have any bright ideas for Access' tendency to add square brackets when it parses queries, then tell you that the query syntax is invalid. In my case, I'm trying to do a LEFT...
9
by: Barton | last post by:
Hello, I just made to move to ASP. I have been developing in PHP the past two years. I must say that I'm a little disappointed in the quality of the beginners tutorials. They don't go further...
1
by: Greg | last post by:
I have an Access db (actually, about 60 of them) that has a table with a field named Q#. This table gets read into a dataset. In the dataset, the field is also called Q#. But when I try to update...
8
by: Jim Michaels | last post by:
C:\prj\quiz\withusers>php tareports.php PHP Parse error: syntax error, unexpected T_ELSE in C:\prj\quiz\withusers\tareports.php on line 205 this is the section of code. if (isset($row4)) {...
4
by: Nunzio | last post by:
I am trying to build an email address in PHP code using v5.1.2. All works well until I try to surround the email address with angle brackets. Every method I try causes the email address to...
9
by: netimen | last post by:
I have a text containing brackets (or what is the correct term for '>'?). I'd like to match text in the uppermost level of brackets. So, I have sth like: 'aaaa 123 < 1 aaa < t bbb < a <tt ff 2...
4
by: maveri4201 | last post by:
I have written a php script (test3.php), which I attached as a text file. Its includes are also attached as text files. I'm trying to run the script here: http://www.wondergy.com/phptestbed/test3.php...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.