1. Computing & Technology

Discuss in my forum

Literal Loop

By , About.com Guide

Level: Beginner

Focus: Loops, Hexadecimal Numbers, Octal Numbers

Literal Loop Question

Values can be assigned to variables using literals. For example, a hexadecimal literal can assign a value to an int variable:


int hexNumber = 0xEF;

Likewise with an octal literal:


int octalNumber = 0647;

The question is can you write a for loop using hexadecimal and octal literals? More specifically can you write one that starts the iteration variable at 0xEF and stops looping once it equals the value 0647? And, how many times will the for loop go around?

To get the most out of this question try and figure out the answer before coming back to read the solution on the next page.

©2012 About.com. All rights reserved.

A part of The New York Times Company.