Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:59:11+00:00 2026-06-12T01:59:11+00:00

I was looking at another page here on stackoverflow and came across a working

  • 0

I was looking at another page here on stackoverflow and came across a working implementation of cycle sort, but I don’t understand how a statement with a semicolon can exist before the curly braces in a while loop. I thought that the while loop is supposed to completely terminate and take no further actions once it finds a statement with a semicolon, so how is it that the code within the curly braces is getting executed? At first glance, I would interpret this as “var” gets incremented with each iteration of the while loop – but I know this is not the case because removing it from that spot and putting the “var++” inside of the curly braces causes an infinite loop.

Under exactly which condition is “var” incremented? Either an explanation, or a link that explains similar syntax:

while (checkSomeBool) var++;
{
   //other stuff happening in here
}

would be appreciated. Thank you. Below is the code taken from CycleSort

public static final <T extends Comparable<T>> int cycleSort(final T[] array) {
int writes = 0;

// Loop through the array to find cycles to rotate.
for (int cycleStart = 0; cycleStart < array.length - 1; cycleStart++) {
  T item = array[cycleStart];

  // Find where to put the item.
  int pos = cycleStart;
  for (int i = cycleStart + 1; i < array.length; i++)
    if (array[i].compareTo(item) < 0) pos++;

  // If the item is already there, this is not a cycle.
  if (pos == cycleStart) continue;

  // Otherwise, put the item there or right after any duplicates.
  <while (item.equals(array[pos])) pos++;
  {
    final T temp = array[pos];
    array[pos] = item;
    item = temp;
  }
  writes++;

  // Rotate the rest of the cycle.
  while (pos != cycleStart) {
    // Find where to put the item.
    pos = cycleStart;
    for (int i = cycleStart + 1; i < array.length; i++)
      if (array[i].compareTo(item) < 0) pos++;

    // Put the item there or right after any duplicates.
    while (item.equals(array[pos])) pos++;
    {
      final T temp = array[pos];
      array[pos] = item;
      item = temp;
    }
    writes++;
  }
} 
return writes;

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:59:12+00:00Added an answer on June 12, 2026 at 1:59 am

    The while loop ends with var++

    while (checkSomeBool) var++; // while ends here
    

    The code after that is not part of the while loop at all.

    {
       //other stuff happening in here - not part of the while loop
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to another Delphi-version question but still different; I'm looking for a
Looking at the layout here , I want to constrain the entire page's min
Got some solved troubles, but want to ask, maybe here is another solution. Here
Ive been looking all over but couldn't find anything so I am here to
I asked a related question a week ago, but here's another problem I'm facing.
I am looking for another book beside Head First Servlets and JSP . The
I'm looking for another way of doing the following: function call_any_function(func, parameters){ // func
Looking to produce some effects using particles bleeding into one another and slowly fading
I'm looking to copy a row from one sheet to another based upon having
I was looking to implement a python script that called another script and captured

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.