Results 1 to 7 of 7
Like Tree3Likes
  • 3 Post By JosAH

Thread: for loop - not a statement

  1. #1
    Keesjuh is offline Member
    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0

    Default for loop - not a statement

    Im making a nested loop but for some reasons I cant seem to find what the problem is. Looked on the web but most reasons why the "not a statement" error is given is because people forgot the semicolon. The error appears on both loops. Can someone help me?

    int i = 0;
    int j = 0;
    File f;

    for (list[i]; i == list.length-1; i++){
    for (j; j == list[i]; j++){

    }

    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: for loop - not a statement

    When posting code, please use the code tags so we can read your code. Also, code should be in the form of an SSCCE, not a snippet but not your whole program either.

    I recommend looking at the syntax for a for loop more closely. What are you initializing in each loop?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Keesjuh is offline Member
    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0

    Default Re: for loop - not a statement

    Thanks Kevin, i didnt know that it were called code tags!

    Java Code:
    public static void main(String[] args) {
            int cntr = 0;
            int[] list = new int[10];
            int arraycntr = 0;
    
            try {
                DataInputStream is = new DataInputStream(new FileInputStream("D:\\Documents\\NetBeansProjects\\ByteCheck\\build\\classes\\bytecheck\\tryoutfile.img"));
    
                while (is.available() > 0) {
                    try {
                        if (check(is)) {
                            list[arraycntr] = cntr;
                            arraycntr++;
                            cntr++;
                            is.readByte();
                        } else {
                            cntr++;
                            is.readByte();
                        }
                    } catch (IOException e) {
                        int i = 0;
                        int j = 0;
                        File f;
                        
                        for (list[i]; i == list.length-1; i++){
                            for (j; j == list[i]; j++){
                                
                            }
                            
                        }
    What I am trying to do is make a program that reads bytes of a file which contains several .jpg images and transports the bytes of these individual .jpgs into individual files. The outer loop is meant to keep count of how many images there are and to repeat the copying procedure for every file. The inner loop is meant to copy all bytes from the file and repeat the copy for every byte until the next .jpg is reached.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: for loop - not a statement

    I recommend reading the tutorial on for loops: The for Statement (The Java Tutorials > Learning the Java Language > Language Basics)

    Basically, a for loop contains 3 things: an assignment, an evaluation, and an increment. The first part of each of your for loops, which should be assignment statements, simply contain values. That's not the proper syntax, so you get a compiler error.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default Re: for loop - not a statement

    Quote Originally Posted by KevinWorkman View Post
    The first part of each of your for loops, which should be assignment statements, simply contain values.
    That is not totally true; it should be an expression statement; an assignment is an expression statement; the expression 'list[ i ]' (as in the OP's example) isn't a statement.

    kind regards,

    Jos

    edit: corrected myself (again)
    Last edited by JosAH; 07-16-2013 at 04:36 PM.
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: for loop - not a statement

    What Jos said!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Keesjuh is offline Member
    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0

Similar Threads

  1. How to add loop statement
    By Hawks in forum New To Java
    Replies: 4
    Last Post: 02-24-2013, 10:24 PM
  2. need help with if statement in loop
    By Snackers in forum New To Java
    Replies: 4
    Last Post: 01-11-2013, 07:04 PM
  3. If Else Statement in While Loop
    By rockintyler in forum New To Java
    Replies: 3
    Last Post: 02-23-2012, 11:33 PM
  4. Help with loop statement
    By arvind1508 in forum New To Java
    Replies: 2
    Last Post: 02-23-2011, 04:39 PM
  5. Need help with a loop statement
    By sunshine39 in forum New To Java
    Replies: 7
    Last Post: 11-03-2008, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •