Skip to main content
Commonmark migration
Source Link

##Bugs##

Bugs

Your code doesn't actually do what it says it will do. The problems are here:

    for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){

        printElements(i,ele);

        // Increment Operations for the next elements(maybe another 99 or less than 99)
        i=(ele+1);
        if((ele+read_max_size > input_list_size)){
            ele=input_list_size;
        }else{
            ele=ele+ele;
        }
    }

Problem one

On the first iteration, only 98 items will be printed instead of 99. This is because ele is set to read_max_size-1 which is 98, so printElements() will end up printing the elements from 0..97 instead of 0..98.

Problem two

After each iteration, you do ele=ele+ele;. This is incorrect because it doubles the end index instead of adding 99 to it. So while the 2nd iteration will be ok, the third iteration will end up printing 198 elements instead of 99. The fourth iteration will print 396 elements, etc.

You should replace that line with ele += read_max_size;.

Problem three

On the first iteration, there is no check to see if ele exceeds the array bounds. So if the array is smaller than read_max_size, you will get an out of bounds exception.

Problem four

You are setting i=(ele+1); after each iteration. By doing that, you are skipping one element. It should be i = ele; instead.

##Rewritten loop##

Rewritten loop

Here is how the loop could have been written to avoid the problems:

    for (int start = 0; start < input_list_size; start += read_max_size) {
        int end = start + read_max_size;
        if (end > input_list_size) {
            end = input_list_size;
        }
        printElements(start, end);
    }

##Bugs##

Your code doesn't actually do what it says it will do. The problems are here:

    for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){

        printElements(i,ele);

        // Increment Operations for the next elements(maybe another 99 or less than 99)
        i=(ele+1);
        if((ele+read_max_size > input_list_size)){
            ele=input_list_size;
        }else{
            ele=ele+ele;
        }
    }

Problem one

On the first iteration, only 98 items will be printed instead of 99. This is because ele is set to read_max_size-1 which is 98, so printElements() will end up printing the elements from 0..97 instead of 0..98.

Problem two

After each iteration, you do ele=ele+ele;. This is incorrect because it doubles the end index instead of adding 99 to it. So while the 2nd iteration will be ok, the third iteration will end up printing 198 elements instead of 99. The fourth iteration will print 396 elements, etc.

You should replace that line with ele += read_max_size;.

Problem three

On the first iteration, there is no check to see if ele exceeds the array bounds. So if the array is smaller than read_max_size, you will get an out of bounds exception.

Problem four

You are setting i=(ele+1); after each iteration. By doing that, you are skipping one element. It should be i = ele; instead.

##Rewritten loop##

Here is how the loop could have been written to avoid the problems:

    for (int start = 0; start < input_list_size; start += read_max_size) {
        int end = start + read_max_size;
        if (end > input_list_size) {
            end = input_list_size;
        }
        printElements(start, end);
    }

Bugs

Your code doesn't actually do what it says it will do. The problems are here:

    for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){

        printElements(i,ele);

        // Increment Operations for the next elements(maybe another 99 or less than 99)
        i=(ele+1);
        if((ele+read_max_size > input_list_size)){
            ele=input_list_size;
        }else{
            ele=ele+ele;
        }
    }

Problem one

On the first iteration, only 98 items will be printed instead of 99. This is because ele is set to read_max_size-1 which is 98, so printElements() will end up printing the elements from 0..97 instead of 0..98.

Problem two

After each iteration, you do ele=ele+ele;. This is incorrect because it doubles the end index instead of adding 99 to it. So while the 2nd iteration will be ok, the third iteration will end up printing 198 elements instead of 99. The fourth iteration will print 396 elements, etc.

You should replace that line with ele += read_max_size;.

Problem three

On the first iteration, there is no check to see if ele exceeds the array bounds. So if the array is smaller than read_max_size, you will get an out of bounds exception.

Problem four

You are setting i=(ele+1); after each iteration. By doing that, you are skipping one element. It should be i = ele; instead.

Rewritten loop

Here is how the loop could have been written to avoid the problems:

    for (int start = 0; start < input_list_size; start += read_max_size) {
        int end = start + read_max_size;
        if (end > input_list_size) {
            end = input_list_size;
        }
        printElements(start, end);
    }
added 201 characters in body
Source Link
JS1
  • 28.9k
  • 3
  • 42
  • 83

##Bugs##

Your code doesn't actually do what it says it will do. The problems are here:

    for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){

        printElements(i,ele);

        // Increment Operations for the next elements(maybe another 99 or less than 99)
        i=(ele+1);
        if((ele+read_max_size > input_list_size)){
            ele=input_list_size;
        }else{
            ele=ele+ele;
        }
    }

Problem one

On the first iteration, only 98 items will be printed instead of 99. This is because ele is set to read_max_size-1 which is 98, so printElements() will end up printing the elements from 0..97 instead of 0..98.

Problem two

After each iteration, you do ele=ele+ele;. This is incorrect because it doubles the end index instead of adding 99 to it. So while the 2nd iteration will be ok, the third iteration will end up printing 198 elements instead of 99. The fourth iteration will print 396 elements, etc.

You should replace that line with ele += read_max_size;.

Problem three

On the first iteration, there is no check to see if ele exceeds the array bounds. So if the array is smaller than read_max_size, you will get an out of bounds exception.

Problem four

You are setting i=(ele+1); after each iteration. By doing that, you are skipping one element. It should be i = ele; instead.

##Rewritten loop##

Here is how the loop could have been written to avoid the problems:

    for (int start = 0; start < input_list_size; start += read_max_size) {
        int end = start + read_max_size;
        if (end > input_list_size) {
            end = input_list_size;
        }
        printElements(start, end);
    }

##Bugs##

Your code doesn't actually do what it says it will do. The problems are here:

    for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){

        printElements(i,ele);

        // Increment Operations for the next elements(maybe another 99 or less than 99)
        i=(ele+1);
        if((ele+read_max_size > input_list_size)){
            ele=input_list_size;
        }else{
            ele=ele+ele;
        }
    }

Problem one

On the first iteration, only 98 items will be printed instead of 99. This is because ele is set to read_max_size-1 which is 98, so printElements() will end up printing the elements from 0..97 instead of 0..98.

Problem two

After each iteration, you do ele=ele+ele;. This is incorrect because it doubles the end index instead of adding 99 to it. So while the 2nd iteration will be ok, the third iteration will end up printing 198 elements instead of 99. The fourth iteration will print 396 elements, etc.

You should replace that line with ele += read_max_size;.

Problem three

On the first iteration, there is no check to see if ele exceeds the array bounds. So if the array is smaller than read_max_size, you will get an out of bounds exception.

##Bugs##

Your code doesn't actually do what it says it will do. The problems are here:

    for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){

        printElements(i,ele);

        // Increment Operations for the next elements(maybe another 99 or less than 99)
        i=(ele+1);
        if((ele+read_max_size > input_list_size)){
            ele=input_list_size;
        }else{
            ele=ele+ele;
        }
    }

Problem one

On the first iteration, only 98 items will be printed instead of 99. This is because ele is set to read_max_size-1 which is 98, so printElements() will end up printing the elements from 0..97 instead of 0..98.

Problem two

After each iteration, you do ele=ele+ele;. This is incorrect because it doubles the end index instead of adding 99 to it. So while the 2nd iteration will be ok, the third iteration will end up printing 198 elements instead of 99. The fourth iteration will print 396 elements, etc.

You should replace that line with ele += read_max_size;.

Problem three

On the first iteration, there is no check to see if ele exceeds the array bounds. So if the array is smaller than read_max_size, you will get an out of bounds exception.

Problem four

You are setting i=(ele+1); after each iteration. By doing that, you are skipping one element. It should be i = ele; instead.

##Rewritten loop##

Here is how the loop could have been written to avoid the problems:

    for (int start = 0; start < input_list_size; start += read_max_size) {
        int end = start + read_max_size;
        if (end > input_list_size) {
            end = input_list_size;
        }
        printElements(start, end);
    }
added 201 characters in body
Source Link
JS1
  • 28.9k
  • 3
  • 42
  • 83

##Bugs##

Your code doesn't actually do what it says it will do. The problem isproblems are here:

    for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){

        printElements(i,ele);

        // Increment Operations for the next elements(maybe another 99 or less than 99)
        i=(ele+1);
        if((ele+read_max_size > input_list_size)){
            ele=input_list_size;
        }else{
            ele=ele+ele;
        }
    }

Problem one

On the first iteration, only 98 items will be printed instead of 99. This is because ele is set to read_max_size-1 which is 98, so printElements() will end up printing the elements from 0..97 instead of 0..98.

Problem two

After each iteration, you do ele=ele+ele;. This is incorrect because it doubles the end index instead of adding 99 to it. So while the 2nd iteration will be ok, the third iteration will end up printing 198 elements instead of 99. The fourth iteration will print 396 elements, etc.

You should replace that line with ele += read_max_size;.

Problem three

On the first iteration, there is no check to see if ele exceeds the array bounds. So if the array is smaller than read_max_size, you will get an out of bounds exception.

##Bugs##

Your code doesn't actually do what it says it will do. The problem is here:

    for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){

        printElements(i,ele);

        // Increment Operations for the next elements(maybe another 99 or less than 99)
        i=(ele+1);
        if((ele+read_max_size > input_list_size)){
            ele=input_list_size;
        }else{
            ele=ele+ele;
        }
    }

Problem one

On the first iteration, only 98 items will be printed instead of 99. This is because ele is set to read_max_size-1 which is 98, so printElements() will end up printing the elements from 0..97 instead of 0..98.

Problem two

After each iteration, you do ele=ele+ele;. This is incorrect because it doubles the end index instead of adding 99 to it. So while the 2nd iteration will be ok, the third iteration will end up printing 198 elements instead of 99. The fourth iteration will print 396 elements, etc.

You should replace that line with ele += read_max_size;.

##Bugs##

Your code doesn't actually do what it says it will do. The problems are here:

    for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){

        printElements(i,ele);

        // Increment Operations for the next elements(maybe another 99 or less than 99)
        i=(ele+1);
        if((ele+read_max_size > input_list_size)){
            ele=input_list_size;
        }else{
            ele=ele+ele;
        }
    }

Problem one

On the first iteration, only 98 items will be printed instead of 99. This is because ele is set to read_max_size-1 which is 98, so printElements() will end up printing the elements from 0..97 instead of 0..98.

Problem two

After each iteration, you do ele=ele+ele;. This is incorrect because it doubles the end index instead of adding 99 to it. So while the 2nd iteration will be ok, the third iteration will end up printing 198 elements instead of 99. The fourth iteration will print 396 elements, etc.

You should replace that line with ele += read_max_size;.

Problem three

On the first iteration, there is no check to see if ele exceeds the array bounds. So if the array is smaller than read_max_size, you will get an out of bounds exception.

Source Link
JS1
  • 28.9k
  • 3
  • 42
  • 83
Loading