Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C++/C Programming › A for() loop in a for() loop

A for() loop in a for() loop

Posts 1–10 of 10 · Page 1 of 1
BO
BooYa
A for() loop in a for() loop
Can be closed, I'm an idiot
#1 · edited 16y ago · 16y ago
why06
why06
Brackets are your friends.
Code:
    int numbers[] = { 1, 1, 2, 4, 4, 5, 7, 8, 8, 9 };
    int i, j;
    
    for(i=0; i<10; i++)
    {
    for(j=i+1; j<10; j++)
    {
    if(numbers[i] == numbers[j]) 
    cout << "Duplicate values are: " << numbers[i] << endl;
    }
    }
#2 · 16y ago
BO
BooYa
Brackets aren't needed here, i just don't understand how these for loops work.
#3 · 16y ago
why06
why06
I'm pretty damn sure you need brackets... and even if you don't you should add them anyway, it makes it easier for people to read your code.

But anyway I see your problem. Your making j = i +1. You should make j=0. That was say the second for loop will be able to look through the entire array to find a match for element [i].
#4 · 16y ago
LA
lalakijilp
you can also add cout statement to make it more clear.
Code:
    int numbers[] = { 1, 1, 2, 4, 4, 5, 7, 8, 8, 9 };
    int i, j;
    
    for(i=0; i<10; i++)
    {
      cout << "i is now" << i <<endl;
        for(j=i+1; j<10; j++)
              {
                cout << "j is now" << j <<endl;
               if(numbers[i] == numbers[j]) 
               cout << "Duplicate values are: " << numbers[i] << endl;
              }           
    }
#5 · 16y ago
BO
BooYa
Quote Originally Posted by why06 View Post
I'm pretty damn sure you need brackets... and even if you don't you should add them anyway, it makes it easier for people to read your code.

But anyway I see your problem. Your making j = i +1. You should make j=0. That was say the second for loop will be able to look through the entire array to find a match for element [i].
lol read my question, the code works fine but i simply dont understand how it works
#6 · 16y ago
why06
why06
Quote Originally Posted by BooYa View Post
lol read my question, the code works fine but i simply dont understand how it works
So you don't know how a for loop works?
#7 · 16y ago
Hell_Demon
Hell_Demon
Code:
for(int i = 0/*Init I as 0*/; i<10/*if I is below 10*/;i++/*increment it*/)
#8 · 16y ago
BO
BooYa
Hmm never mind... I just didn't understand how the second for loop would work inside the first and why j was set to i+1, but i understand now after trying those cout statements from laka
#9 · 16y ago
why06
why06
Ok...if you want me to... and thanks lalakiljip.
#10 · 16y ago
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Similar Threads

  • [Source]FOR LoopsBy HypnoticBabeTrap in C++/C Programming
    13Last post 16y ago
  • 2 for(;;) loopsBy maarten551 in Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    5Last post 15y ago
  • [HELP]"for" loopBy Drake in C++/C Programming
    4Last post 15y ago
  • Hacks for mmorpg?By suppaman in General Game Hacking
    6Last post 15y ago
  • Too Ownage For Words.By Flawless in Art & Graphic Design
    8Last post 20y ago

Tags for this Thread

#loop