Computer Science, asked by sandeepsharma63, 4 months ago

Where is empty loop used in java????
please don't answer for points if you don't know then do not answer​

Answers

Answered by nikiniki2111
0

Answer:

An empty loop contain only one empty statement. They are mostly used to produce time breaks. for(int a=0;a<10;a++); An infinite loop on the other hand continues forever.

please mark me as brainliest and follow me

Answered by sakash20207
0

Name: Empty branch of conditional, or empty loop body

Description: An undocumented empty block or statement hinders readability. It may also indicate incomplete code.

ID: java/empty-block

Kind: problem

Severity: warning

Precision: low

Query: EmptyBlock.ql

/**

* @name Empty branch of conditional, or empty loop body

* @description An undocumented empty block or statement hinders readability. It may also

* indicate incomplete code.

* @kind problem

* @problem.severity warning

* @precision low

* @id java/empty-block

* @tags reliability

* readability

*/

import semmle.code.java.Statement

/** A block without statements or comments. */

private Block emptyBlock() {

result.getNumStmt() = 0 and

result.getLocation().getNumberOfCommentLines() = 0

}

/** Auxiliary predicate: file and line of a comment. */

private predicate commentedLine(File file, int line) {

exists(JavadocText text, Location loc |

loc = text.getLocation() and

loc.getFile() = file and

loc.getStartLine() = line and

loc.getEndLine() = line

)

}

/** An uncommented empty statement */

private EmptyStmt emptyStmt() {

not commentedLine(result.getFile(), result.getLocation().getStartLine())

}

/** An empty statement or an empty block. */

Stmt emptyBody() { result = emptyBlock() or result = emptyStmt() }

/**

* Empty blocks or empty statements should not occur as immediate children of if-statements or loops.

* Empty blocks should not occur within other blocks.

*/

predicate blockParent(Stmt empty, string msg) {

empty = emptyBody() and

(

empty.getParent() instanceof IfStmt and

msg = "The body of an if statement should not be empty."

or

empty.getParent() instanceof LoopStmt and msg = "The body of a loop should not be empty."

or

empty.getParent() instanceof Block and

empty instanceof Block and

msg = "This block should not be empty."

)

}

from Stmt empty, string msg

where

empty = emptyBody() and

blockParent(empty, msg)

select empty, msg + " Typographical error or missing code?"

An unexplained empty block or statement makes the code less readable. It might also indicate missing code, a misplaced semicolon, or a misplaced brace. For these reasons, it should be avoided.

Recommendation

If a block is empty because some code is missing, add the code.

If an if statement has an empty then branch and a non-empty else branch, it may be possible to negate the condition and move the statements of the else branch into the then branch.

If a block is deliberately empty, add a comment to explain why.

Example

In the following example, the while loop has intentionally been left empty. The purpose of the loop is to scan a String for the first occurrence of the character '='. A programmer reading the code might not understand the reason for the empty loop body, and think that something is missing, or perhaps even that the loop is useless. Therefore it is a good practice to add a comment to an empty block explaining why it is empty.

public class Parser

{

public void parse(String input) {

int pos = 0;

// ...

// AVOID: Empty block

while (input.charAt(pos++) != '=') { }

// ...

}

}

PLEASE MARK ME AS BRAINLIEST HAVE A GOOD DAY TO YOU

Similar questions