Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
¿Cómo imprimir números pares usando un bucle for?

Encuentro este simple ejercicio "for loop".

Usando un bucle for, imprima todos los números pares hasta n inclusive. No incluya 0.

 let n1 = 22; // Example output: // 2 4 6 8 10 12 14 16 18 20 22 OR each item on a new line

Encontré una manera de resolver esto, pero no creo que sea elegante en absoluto.

Aquí está mi código:

 let n1 = 22; for (let i = 0; i < n1; i++){ let b = i * 2; if (b <= n1){ if (b == 0) {} else { console.log('Count',b);} }; };

¿Cómo puedo mejorarlo?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Solo cuenta de dos en dos:

 for (let i=2; i <= 22; i+=2) { console.log('Count', i); }

about 4 years ago · Juan Pablo Isaza Report

0

 for (let i=2; i <= 22; i+=2) { console.log(i); }

mis mejores deseos

about 4 years ago · Juan Pablo Isaza Report

0

Aquí usando el bucle while :

 const count = { index: 0, n1: 22 } while(count.index < count.n1) { console.log('Count', count.index += 2) }

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!