trying to print a square of X's and Y's using nested for loops

Input: 3 7 4 Output: XXXY XXYY XYYY XXXXXXXY XXXXXXYY XXXXXYYY XXXXYYYY XXXYYYYY XXYYYYYY XYYYYYYY XXXXY XXXYY XXYYY XYYYY I have an idea that involves 2 for loops nested in another for loop that would look something like: String ret = ""; for (int row = 0; row < size; row++) //size is the input… Read More trying to print a square of X's and Y's using nested for loops

Undefined when reading length with nested for loops in JAVA SCRIPT

let arr=[[1,2,3],[4,5,6],[7,8,9]]; for (let i=arr.length;i>=0;i–){ console.log(arr[i]); for (let n=arr[i].length;n>=0;n–){ console.log(arr[i][n]); } } >Solution : You are trying to read out of range of arrays. Add -1 let arr = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]; for (let i = arr.length – 1; i >= 0; i–) { console.log(arr[i]); for (let… Read More Undefined when reading length with nested for loops in JAVA SCRIPT

Elegant solution – Nested for loops (eslint no-await-in-loop)

I have some code that works broadly as follows: function getRegionUsers(region) { return new Promise((resolve) => { setTimeout(() => { if (region === "emea") { return resolve(["dave", "mike", "steve"]); } return resolve(["kiki", "maya", "yukiko"]); }, 1000); }); } function sendMail(user, region) { console.info(`sendMail called: ${user} (${region})`); } async function test() { const regions = ["emea",… Read More Elegant solution – Nested for loops (eslint no-await-in-loop)

Bash Shell nested for loop on multiple arrays doesn't go though all elements

OUTER_LIST=(1 2) INNER_LIST=(a b) for (( i=0; i < ${#OUTER_LIST[@]}; i++ )); do echo "outer…${OUTER_LIST[$i]}" for (( i=0; i < ${#INNER_LIST[@]}; i++ )); do echo "inner…${INNER_LIST[$i]}" done done Output: outer…1 inner…a inner…b Question: why does it loop OUTER_LIST only 1 time ? >Solution : You use the same loop variable, i, in the inner loop… Read More Bash Shell nested for loop on multiple arrays doesn't go though all elements